package com.emapp.lccode.utils;

import android.os.Build;
import android.os.Environment;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: TODO
 * @Author: zhang
 * @Date: 2023/4/25
 */
public class AotuVoiceFileUtils {
    static List<String> pathList = new ArrayList<>();

    public static File pathFile() {
        String parentPath = Environment.getExternalStorageDirectory().getAbsolutePath();
        File childFile = null;
        if (Build.MANUFACTURER.toUpperCase().equals("HUAWEI") || Build.MANUFACTURER.toUpperCase().equals("HONOR")) {
            if (FileUtil.isExist(parentPath + "/Sounds/CallRecord")) {
                childFile = new File(parentPath + "/Sounds/CallRecord");
            } else if (FileUtil.isExist(parentPath + "/record")) {
                childFile = new File(parentPath + "record");
            } else if (FileUtil.isExist(parentPath + "/Record")) {
                childFile = new File(parentPath + "/Record");
            } else {
                childFile = new File("");
            }

        } else if (Build.MANUFACTURER.toUpperCase().equals("XIAOMI")) {
            childFile = new File(parentPath + "/MIUI/sound_recorder/call_rec/");
        } else if (Build.MANUFACTURER.toUpperCase().equals("MEIZU")) {
            childFile = new File(parentPath + "/Recorder");
        } else if (Build.MANUFACTURER.toUpperCase().equals("OPPO")) {
            childFile = new File(parentPath + "/Recordings");
        } else if (Build.MANUFACTURER.toUpperCase().equals("VIVO")) {
            childFile = new File(parentPath + "/Record/Call");
        } else if (Build.MANUFACTURER.toUpperCase().equals("SAMSUNG")) {
            childFile = new File(parentPath + "/Sounds");
        } else {
            childFile = new File("");
        }
        return childFile;
    }

    /*传入拨打的电话号码做匹配*/
    public static String getPathList(String phone) {
        ArrayList<String> result = new ArrayList<>();
        File[] files = pathFile().listFiles();
        if (files == null) {
            return "";
        }
        for (int i = 0; i < files.length; i++) {
            if (!files[i].isDirectory()) {
                String fileName = files[i].getName();
               // if (fileName.trim().toLowerCase().contains(phone)) {
                    result.add(fileName);
               // }
            }
        }

       // return result.isEmpty() ? "" : result.get(0);
        return result.isEmpty() ? "" : result.toString();
    }

}
